package com.hf.wujian.dispatch.imp;

import com.hf.wujian.annotation.Dispatch;
import com.hf.wujian.constant.Command;
import com.hf.wujian.dispatch.BSHDispatch;
import com.hf.wujian.model.GameHall;
import com.hf.wujian.model.GameRoom;
import com.hf.wujian.model.GameUser;
import com.hf.wujian.netty.NettyMsg;
import io.netty.channel.ChannelHandlerContext;

import java.util.List;

/**
 * 获得房间内所有用户用户信息
 *
 * @author hf
 * @date 2018/11/27
 * @version 1.0
 *
 */
@Dispatch(command = Command.COMMAND_GET_ROOM_USER_INFO)
public class GetRoomUserInfoDispatch implements BSHDispatch {

    @Override
    public void dispatch(ChannelHandlerContext ctx, NettyMsg nettyMsg, GameHall gameHall, GameUser gameUser) {
        GameRoom gameRoom = gameUser.getGameRoom();
        if(gameRoom!=null){
            List<String> names = gameRoom.getAllUserName();
            StringBuffer stringBuffer = new StringBuffer();
            for (String name : names) {
                stringBuffer.append(name + ",");
            }
            ctx.writeAndFlush(stringBuffer.toString() + "\r\n");
        }
    }
}
